import 'package:environmental_les_app/common/style/colours.dart';
import 'package:environmental_les_app/common/widgets/button_public_rect.dart';
import 'package:environmental_les_app/common/widgets/common_widget.dart';
import 'package:environmental_les_app/common/widgets/rich_text.dart';
import 'package:environmental_les_app/page/task_list/task_detail/widgets/text_bg_container.dart';
import 'package:environmental_les_app/page/task_list/widgets/basic_info_card.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';

import 'index.dart';

class WarningDetailPage extends GetView<WarningDetailController> {
  const WarningDetailPage({super.key});

  // 主视图
  Widget _buildView() {
    return Column(
      children: [
        const MyPageAppBar(
          backgroundColor: Colors.transparent,
          title: "预警详情",
        ),
        vGap10,
        Expanded(
          child: SingleChildScrollView(
            child: Column(
              children: [
                const Padding(
                  padding: EdgeInsets.symmetric(horizontal: 10),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text("待处理",
                          style: TextStyle(
                              fontSize: 24,
                              fontWeight: FontWeight.w600,
                              color: Colors.black)),
                      Row(
                        children: [
                          RichTextWidget(children: [
                            TextSpan(
                                text: '报警次数/处理次数：',
                                style: TextStyle(
                                    fontSize: 14,
                                    color: Colours.text09C,
                                    fontWeight: FontWeight.normal)),
                            TextSpan(
                                text: '5/2',
                                style: TextStyle(
                                    fontSize: 14,
                                    color: Colours.appMain,
                                    fontWeight: FontWeight.normal)),
                          ]),
                          Icon(
                            Icons.arrow_right,
                            color: Colours.icon96BEFF,
                          )
                        ],
                      )
                    ],
                  ),
                ),
                vGap10,
                _buildWarningInfoCard(), // 基本信息卡片
                Visibility(
                    visible: true, child: _buildProcessFlowCard()), // 处理流程卡片
              ],
            ),
          ),
        ),
        Container(
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
          child: Row(
            children: [
              Expanded(child: ButtonPublicRect(text: "创建任务", onPressed: () {})),
              hGap10,
              Expanded(child: ButtonPublicRect(text: "审批处理", onPressed: () {})),
            ],
          ),
        ),
      ],
    );
  }

  Widget _buildWarningInfoCard() {
    bool isExpanded = controller.expansionState['warningInfo'] ?? true;
    return BasicInfoCard(
      title: "基本信息",
      cardKey: 'warningInfo',
      isExpanded: isExpanded,
      onTap: () => controller.toggleCard('warningInfo'),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Container(
                padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
                decoration: BoxDecoration(
                  color: Colours.bgF4F7FE,
                  borderRadius: BorderRadius.circular(4),
                  border: Border.all(color: Colours.lineB7C0D7),
                ),
                child: const Text(
                  "无人机监测",
                  style: TextStyle(
                      color: Colours.appMain,
                      fontSize: 13,
                      fontWeight: FontWeight.w500),
                ),
              ),
              hGap8,
              const Text(
                "环保局",
                style: TextStyle(
                    color: Colours.textC4C,
                    fontSize: 17,
                    fontWeight: FontWeight.w500),
              )
            ],
          ),
          vGap15,
          buildAddressInfoRow("报警地点:", "准格尔旗薛家湾镇环保局准格尔旗薛家湾镇环保局"),
          vGap10,
          TextBgContainer(
            child: buildInfoRow("报警时间:", "2025-08-22 11:29:55"),
          ),
          vGap10,
          TextBgContainer(
              child: buildExplanationInfoRow(
                  "任务说明", "这是具体的描述信息这是具体的描述信息这是具体的描述信息")),
          vGap10,
        ],
      ),
    );
  }

  // 处理流程卡片
  Widget _buildProcessFlowCard() {
    bool isExpanded = controller.expansionState['processFlow'] ?? true;
    return BasicInfoCard(
      title: "处理流程",
      cardKey: 'processFlow',
      onTap: () => controller.toggleCard('processFlow'),
      isExpanded: isExpanded,
      child: Column(
        children: [
          buildProcessStep("05", "创建任务", "2024/11/11 11:11:11", "值守中心", "王二",
              "任务说明这是说明说明这是说明说明这是说明说明", "执法大队部门", true),
          buildProcessStep("04", "审批处理", "2024/11/11 11:11:11", "值守指挥中心", "王二",
              null, "执法大队部门", true),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<WarningDetailController>(
      init: WarningDetailController(),
      id: "warning_detail",
      builder: (_) {
        return Scaffold(
          body: Stack(
            children: [
              Container(
                height: 200,
                decoration: BoxDecoration(
                    image: DecorationImage(
                  image: AssetImage(ImageUtils.getImgPath("bg_title_top")),
                  fit: BoxFit.cover,
                )),
              ),
              _buildView(),
            ],
          ),
        );
      },
    );
  }
}
